#Java - Code Snippets for '#Tricky code examples' - 2 code snippet(s) found |
|
Sample 1. Tricky code for String Comparison and String Pool | |
|
class BuggyBread {
public static void main(String[] args)
{
String s2 = "I am unique!";
String s5 = "I am unique!";
System.out.println(s2 == s5); // prints true
}
}
|
|
Like Feedback tricky code example string string comparison object comparison object equality string equality string pool |
|
|
Sample 2. Tricky Code for Overloading and Overriding | |
|
class BuggyBread1 {
public String method() {
return "Base Class - BuggyBread1";
}
}
class BuggyBread2 extends BuggyBread1{
private static int counter = 0;
public String method(int x) {
return "Derived Class - BuggyBread2";
}
public static void main(String[] args) {
BuggyBread1 bg = new BuggyBread2();
System.out.println(bg.method()); // prints Base Class - BuggyBread1
}
}
|
|
Like Feedback overloading overriding tricky code examples inheritance |
|
|